import { createApp } from 'vue'
import {createPinia} from 'pinia'

import './style.css'
import App from './App.vue'

import Antd from 'ant-design-vue';

import { setupRouter } from './router'

import {
    renderWithQiankun,
    qiankunWindow,
    QiankunProps
} from 'vite-plugin-qiankun/dist/helper'


import VConsole from 'vconsole';
new VConsole()



const pinia = createPinia()


let app:any = null

const render = (props:any = {} )=>{
    const {container} = props
    app = createApp(App)
    const c = container?.querySelector('#app') || '#app'  //避免id重复导致微应用挂载失败
    app.use(pinia)

    setupRouter(app)
    app.use(Antd);
    app.mount(c)
}


const initQianKun = () => {
    renderWithQiankun({
        bootstrap(){
            console.log('微应用：bootstrap')
        },
        mount(props:any){
           //  获取主应用传入数据
           console.log('微应用:mount',props)
           render(props)
       },
       unmount(props:any){
           console.log('微应用:unmount',props)
           app.unmount()//离开销毁
       },
       update(props:any){
           console.log('微应用:update',props)
       }
    })
}

console.log('组件加载--qiankunwindow',qiankunWindow)
console.log('组件加载--qiankunwindow.__POWERED_BY_QIANKUN',qiankunWindow.__POWERED_BY_QIANKUN__)
qiankunWindow.__POWERED_BY_QIANKUN__ ? initQianKun() : render()   //判断是否使用 qiankun ，i保证项目可以独立运行





// async function main() {
//     const app = createApp(App)
//     setupRouter(app)
//     app.use(Antd);

//     app.mount('#app')
// }

// main()
